package csel.model;

import csel.model.entity.*;
import junit.framework.TestCase;
import org.junit.Before;
import org.junit.Test;

public class TestMovement extends TestCase
{
	Model model;
	
	@Before
	public void setUp()
	{
		model = new Model();
	}
	
	@Test
	public void testCharacterDirectMove() throws java.io.IOException
	{
		GameFactory.makeNewGame(new Smasher(), "tiger PUNCH", model);
		
		subTestDirectMove();
	}
	
	private void subTestDirectMove()  // separate in case we want to try loading
	{
		PlayerCharacter pc;
		Map map;
		Tile t;
		
		pc = model.getPlayerCharacter();
		map = model.getMap();
		
		assertNotNull(pc.getTile());
		assertNotNull(pc.getLocation());
		
		t = map.getTile(8, 8);
		
		assertTrue("move() failed.", pc.move(t));
		
		assertEquals(t, pc.getTile());
	}
	
	@Test
	public void testCharacterDirectionalMove() throws java.io.IOException
	{
		PlayerCharacter pc;
		Map map;
		
		GameFactory.makeNewGame(new Smasher(), "tiger PUNCH", model);

		pc = model.getPlayerCharacter();
		map = model.getMap();

		assertNotNull(pc.getTile());
		assertNotNull(pc.getLocation());
		
		try
		{
			subTestDirectionalMove(pc, Direction.NORTH);
			Thread.sleep(200);
			subTestDirectionalMove(pc, Direction.SOUTH);
			Thread.sleep(200);
			subTestDirectionalMove(pc, Direction.NORTHWEST);
			Thread.sleep(200);
			subTestDirectionalMove(pc, Direction.SOUTHEAST);
			Thread.sleep(200);
			subTestDirectionalMove(pc, Direction.WEST);
			Thread.sleep(200);
			subTestDirectionalMove(pc, Direction.EAST);
			Thread.sleep(200);
			subTestDirectionalMove(pc, Direction.NORTHEAST);
			Thread.sleep(200);
			subTestDirectionalMove(pc, Direction.SOUTHWEST);
		}
		catch (InterruptedException ex)
		{
			Thread.currentThread().interrupt();
		}
	}
	
	private void subTestDirectionalMove(PlayerCharacter pc, Direction dir)
	{
		Tile t;
		
		t = pc.getTile().getNeighbor(dir);
		assertTrue("moveOne(dir) failed", pc.moveOne(dir));
		assertEquals(t, pc.getTile());
	}
}
